package com.zjj.lbw.microservice.sentinel.app.demo;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhanglei.zjj
 * @description sentinel流控规则-链路流控模式
 * @date 2023/7/29 11:33
 */
@RestController
public class ChainFlowRuleTest {
    @Autowired
    private ChainFlowRuleTest chainFlowRuleTest;

    @GetMapping("/test1")
    public String test1() {
        return chainFlowRuleTest.getUser();
    }

    @GetMapping("/test2")
    public String test2() {
        return chainFlowRuleTest.getUser();
    }

    @SentinelResource(value = "getUser", blockHandler = "handleException")
    public String getUser() {
        return "zjj";
    }

    public String handleException(BlockException ex) {
        return "===被限流降级啦===";
    }
}

